﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lfm.EndPoints
{
    public class Geo
    {
        /// <summary>
        /// Fetches a list of nearby events. Requires location coordinates.
        /// </summary>
        /// <param name="Latitude"> Specifies a latitude value to retrieve events for (service returns nearby events by default)</param>
        /// <param name="Longtitude">Specifies a location to retrieve events for (service returns nearby events by default)</param>
        /// <param name="Distance">Find events within a specified radius (in kilometres)</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 10.</param>
        /// <param name="Page">The page number to fetch. Defaults to first page.</param>
        /// <returns>List of nearby events</returns>
        public static async Task<List<lfm.Event>> getEvents(Double Latitude, Double Longtitude, Int32? Distance, Int32? Limit, Int32? Page)
        {
            String s = String.Format("{0}&method=geo.getevents&lat={1}&long={2}", Base.APIUrl, Uri.EscapeDataString(Latitude.ToString()), Uri.EscapeDataString(Longtitude.ToString()));
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();
            if (Distance.HasValue) s+= "&distance=" + Distance.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Geo.getEvents(await Base.DownloadString(u));
        }
    }
}
